package com.zang.linkedlist;

import java.util.stream.Stream;

/**
 * @author ZVerify
 * @since 2022/10/12 09:23
 **/
public class 环形链表 {

    public boolean hasCycle(ListNode head) {

        ListNode slow = head;
        ListNode fast = head;

        while (true){

            slow = slow.next;
            fast = fast.next.next;
            if (slow==fast){
                return true;
            }else if (slow==null||fast==null) return false;
        }
    }
}
